<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.ui.ActionBuffer</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_ui doc_spec_ui_action_buffer_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../../'>Howl Documentation (master branch)</a></li><li>Spec</li><li>Ui</li><li>Spec - howl.ui.ActionBuffer</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.ui.actionbuffer">howl.ui.ActionBuffer</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">ActionBuffer</span><span class="o">!</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span></pre>&#x000A;&#x000A;<h4 id="behaves-like-a-buffer">behaves like a Buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' world'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello world'</span></pre>&#x000A;&#x000A;<h4 id="does-not-collection-undo-revisions-by-default">does not collection undo revisions by default</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="nc">ActionBuffer</span><span class="p">().</span><span class="n">collect_revisions</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".insert">.insert<span class="arg-list">(object, pos[ , style])</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(with no specified style)</span></h3>&#x000A;&#x000A;<h4 id="inserts-the-object-with-no-specific-style-and-returns-the-next-position">inserts the object with no specific style and returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="returns-&lt;pos&gt;-and-leaves-the-buffer-untouched-for-an-empty-string">returns &lt;pos&gt; and leaves the buffer untouched for an empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="p">(</span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(with style specified)</span></h3>&#x000A;&#x000A;<h4 id="styles-the-object-with-the-specified-style">styles the object with the specified style</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'˫˫'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="p">(</span><span class="s1">'hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">))</span></pre>&#x000A;&#x000A;<h4 id="returns-&lt;pos&gt;-and-leaves-the-buffer-untouched-for-an-empty-string">returns &lt;pos&gt; and leaves the buffer untouched for an empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="p">(</span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=")"><span class="arg-list">(when object is a styled object (.styles is present)</span>)</h3>&#x000A;&#x000A;<h4 id="inserts-the-corresponding-.text-and-returns-the-next-position">inserts the corresponding .text and returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">chunk</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="n">chunk</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foofoo'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="styles-the-inserted-.text-using-.styles-for-the-styling">styles the inserted .text using .styles for the styling</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="p">{</span><span class="ss">text:</span><span class="w"> </span><span class="s1">'styled'</span><span class="p">,</span><span class="w"> </span><span class="ss">styles:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">}},</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'styled'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="still-returns-the-next-position">still returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="nc">StyledText</span><span class="p">(</span><span class="s1">'åö'</span><span class="p">,</span><span class="w"> </span><span class="p">{}),</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="ignores-any-given-&lt;style&gt;-parameter">ignores any given &lt;style&gt; parameter</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="nc">StyledText</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}),</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".append">.append<span class="arg-list">(text, style)</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(with no specified style)</span></h3>&#x000A;&#x000A;<h4 id="appends-the-text-with-no-specific-style-and-returns-the-next-position">appends the text with no specific style and returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="s1">'hello world'</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' world'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">))</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(with style specified)</span></h3>&#x000A;&#x000A;<h4 id="styles-the-text-with-the-specified-style">styles the text with the specified style</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'˫'</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">))</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when object is a styled object)</span></h3>&#x000A;&#x000A;<h4 id="appends-the-corresponding-text-and-returns-the-next-position">appends the corresponding text and returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">chunk</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foofoo'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="styles-the-inserted-text-using-.styles-for-the-styling">styles the inserted text using .styles for the styling</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">object</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">StyledText</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">})</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="n">object</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foobar'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">))</span></pre>&#x000A;&#x000A;<h4 id="still-returns-the-next-position">still returns the next position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="nc">StyledText</span><span class="p">(</span><span class="s1">'åö'</span><span class="p">,</span><span class="w"> </span><span class="p">{})</span></pre>&#x000A;&#x000A;<h4 id="ignores-any-given-&lt;style&gt;-parameter">ignores any given &lt;style&gt; parameter</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="nc">StyledText</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}),</span><span class="w"> </span><span class="s1">'keyword'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="style">style<span class="arg-list">(start_pos, end_pos, style)</span></h2>&#x000A;&#x000A;<h4 id="applies-&lt;style&gt;-for-the-inclusive-text-range-given">applies &lt;style&gt; for the inclusive text range given</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏlɩo'</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="o">\</span><span class="n">style</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="s1">'keyword'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'keyword'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="p">(</span><span class="n">style</span><span class="p">.</span><span class="n">at_pos</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">))</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(resource management)</span></h3>&#x000A;&#x000A;<h4 id="buffers-are-collected-properly">buffers are collected properly</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">ActionBuffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">buffers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">buffers</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="memory-usage-is-stable">memory usage is stable</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert_memory_stays_within</span><span class="w"> </span><span class="s1">'20Kb'</span><span class="p">,</span><span class="w"> </span><span class="mi">50</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">ActionBuffer</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'collect me!'</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
